#ifndef TRGAMECLOCK_H
#define TRGAMECLOCK_H

/*
trGameClock is the main 'pulser'
at the top of the hierarchical
stroke(), crank, and rod system
it is a trEventNode and passes down
E_TIK event messages to the device.
the device grabSpit()s those E_TIK
messages to the trGameWorlds attached
to the device. the gameworlds then
should have a custom system defined
to distribute those messages. an example
would be an external physics library
interface trGameObject derived class
that receives those tiks and sends
appropriate pseudo: E_SECOND plus data
to a pseudo: trPhysicsBolt
*/

/*
the actual core of the clock is taken
from the bullet source, which itself
got the source from "game jewels"
which offers an accurate, small,
efficient, portable clock class.
*/

#include <irrlicht.h>
#include "trEventNode.h"
#include "trGameDevice.h"
#include "LinearMath\btQuickProf.h"

namespace tetra
{

class trGameDevice;
//tik events moved to trEventProfile.h

struct SGameClock
{

    /*networking and I/O is synched with logic
    file read/write is performed on a query and
    stack, first in first serve basis.
    */

    /*@above: phase out.
    I/O, and graphics or other external libraries
    are 'synched' to the gameclock by custom gameobject
    interfaces that themselves deal with the external
    libraries through the game world and that deals with the
    correct trBolt
    */

};

class trGameClock : public trEventNode
{

    irr::u32 previous_time; // last time elapsed in milliseconds
    irr::u32 current_time; // current time in milliseconds

    irr::u32 d_time; //time elapsed since it last checked time in milliseconds

    trGameDevice* game_device;

    btClock* clock_core; //clock in bullet source

public:

    //! Default constructor
    trGameClock();

    //! Constructor
    trGameClock( const SGameClock& clock_data );

    //! Returns time in milliseconds
    irr::u32 getTime();

    //! Returns time in microseconds
    irr::u32 getTimeMicroseconds();

    //! Main logic tik method
    //! This is entered and there is a while loop inside
    void tik();


};

}; //end namespace tetra

#endif //TRGAMECLOCK_H
